home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
wtjmarch.zip
/
SLIDE.ZIP
/
SLIDING.CPP
next >
Wrap
C/C++ Source or Header
|
1991-12-15
|
4KB
|
160 lines
// sliding.cpp
#include"stdwin.h"
#include<stdio.h>
#include<string.h>
const UP = 1;
const DOWN = 0;
const WM_STARTIMER = WM_USER;
const WM_STOPTIMER = WM_USER+1;
const FREQ_DEFAULT = 50;
char *winTitle = "Sliding Text";
class SlidingText : public WinAppStdWindow
{
char *message;
BOOL direction, adjusted;
int LineHeight, ScreenHeight, curY;
WORD frequency;
public:
SlidingText(char *winname, char *msg) : WinAppStdWindow(winname)
{
// insert calls to change window class info here
message = msg;
direction = DOWN;
LineHeight = ScreenHeight = curY = 0;
adjusted = FALSE;
frequency = FREQ_DEFAULT;
}
void WMPAINT(void)
{
PAINTSTRUCT ps;
BeginPaint(hWnd, &ps);
TEXTMETRIC tmFontInfo;
GetTextMetrics(ps.hdc, (LPTEXTMETRIC) &tmFontInfo);
LineHeight = tmFontInfo.tmExternalLeading + tmFontInfo.tmHeight;
if(!adjusted)
{
ScreenHeight -= LineHeight;
adjusted = TRUE;
}
// set alignment flags for centering
SetTextAlign(ps.hdc, TA_CENTER);
RECT rect;
GetClientRect(hWnd,&rect); // new centered rectangle
TextOut(ps.hdc,rect.right/2,curY,message, strlen(message));
EndPaint(hWnd, &ps);
}
void WMTIMER(void)
{
if(curY == ScreenHeight)
direction = UP;
if(curY == 0)
direction = DOWN;
if(direction == DOWN)
{
ScrollWindow(hWnd,0,1,NULL,NULL);
curY++;
}
else
{
ScrollWindow(hWnd,0,-1,NULL,NULL);
curY--;
}
UpdateWindow(hWnd);
}
void WMCREATE(void)
{
StartTimer();
SetTitle();
}
void WMSIZE(void)
{
ScreenHeight = (HIWORD(lParam) - LineHeight);
curY = 0;
}
void WMCLOSE(void) { DestroyWindow(hWnd); }
void WMDESTROY(void) { PostQuitMessage(0); }
// Accept LeftButton and '+' for faster (more frequent) action
// and RightButton and '-' for slower (less frequent) action
void WMLBUTTONDOWN(void) { Faster(); }
void WMRBUTTONDOWN(void) { Slower(); }
void WMCHAR(void)
{
if(wParam == '+')
Faster();
if(wParam == '-')
Slower();
}
void Faster(void)
{
PostMessage(hWnd,WM_STOPTIMER,0,0L);
if(frequency > 0)
frequency -= 10;
PostMessage(hWnd,WM_STARTIMER,0,0L);
SetTitle();
}
void Slower(void)
{
PostMessage(hWnd,WM_STOPTIMER,0,0L);
if(frequency < 65535u)
frequency += 10;
PostMessage(hWnd,WM_STARTIMER,0,0L);
SetTitle();
}
void SetTitle(void)
{
char temp[50];
sprintf(temp,"%s (Speed = %05u)",winTitle,~frequency);
SetWindowText(hWnd, temp);
}
void UserMessages(void);
void WMSTARTTIMER(void)
{
StartTimer();
UserMessageUsed = TRUE;
}
void WMSTOPTIMER(void)
{
StopTimer();
UserMessageUsed = TRUE;
}
void StartTimer(void) { SetTimer(hWnd, 1, frequency, NULL); }
void StopTimer(void) { KillTimer(hWnd,1); }
};
void SlidingText::UserMessages(void)
{
switch(msg)
{
case WM_STARTIMER:
WMSTARTTIMER();
return;
case WM_STOPTIMER:
WMSTOPTIMER();
return;
}
}
int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int)
{ // initialize the object
SlidingText MyWin(winTitle, "Hello Windows from C++");
MyWin.Display(); // open the window
return MyWin.Run(); // process any messages
}